Trò chơi Tic-Tac-Toe, game đánh caro full source code
53.572 lượt xem;
- OnClickRequestOwnership.cs
- DemoChangeOwner /
- Demos /
- Photon Unity Networking /
- Assets /
- project /
1 using UnityEngine;
2 using System.Collections;
3
4 [RequireComponent( typeof( PhotonView ) )]
5 public class OnClickRequestOwnership : Photon.MonoBehaviour
6 {
7
8 public void OnClick()
9 {
10 if( Input.GetKey( KeyCode.LeftShift ) || Input.GetKey( KeyCode.RightShift ) )
11 {
12 Vector3 colVector = new Vector3( Random.Range( 0.0f, 1.0f ), Random.Range( 0.0f, 1.0f ), Random.Range( 0.0f, 1.0f ) );
13 this.photonView.RPC( "ColorRpc", PhotonTargets.AllBufferedViaServer, colVector );
14 }
15 else
16 {
17 if( this.photonView.ownerId == PhotonNetwork.player.ID )
18 {
19 Debug.Log( "Not requesting ownership. Already mine." );
20 return;
21 }
22
23 this.photonView.RequestOwnership();
24 }
25 }
26
27 [RPC]
28 public void ColorRpc( Vector3 col )
29 {
30 Color color = new Color( col.x, col.y, col.z );
31 this.gameObject.GetComponent<Renderer>().material.color = color;
32 }
33 }
2 using System.Collections;
3
4 [RequireComponent( typeof( PhotonView ) )]
5 public class OnClickRequestOwnership : Photon.MonoBehaviour
6 {
7
8 public void OnClick()
9 {
10 if( Input.GetKey( KeyCode.LeftShift ) || Input.GetKey( KeyCode.RightShift ) )
11 {
12 Vector3 colVector = new Vector3( Random.Range( 0.0f, 1.0f ), Random.Range( 0.0f, 1.0f ), Random.Range( 0.0f, 1.0f ) );
13 this.photonView.RPC( "ColorRpc", PhotonTargets.AllBufferedViaServer, colVector );
14 }
15 else
16 {
17 if( this.photonView.ownerId == PhotonNetwork.player.ID )
18 {
19 Debug.Log( "Not requesting ownership. Already mine." );
20 return;
21 }
22
23 this.photonView.RequestOwnership();
24 }
25 }
26
27 [RPC]
28 public void ColorRpc( Vector3 col )
29 {
30 Color color = new Color( col.x, col.y, col.z );
31 this.gameObject.GetComponent<Renderer>().material.color = color;
32 }
33 }